#include "usecolortdegate.h"

#include <QListWidgetItem>
#include <QPixmap>
#include <QStandardItemModel>
#include <QMessageBox>

UseColortDegate::UseColortDegate(QWidget *parent, Qt::WFlags flags)
	: QDialog(parent, flags)
{
	ui.setupUi(this);

 	QColor m_color = QColor(16711680 |0xff000000);
 	QPixmap m_pix = QPixmap(40, 36);
 	m_pix.fill(m_color);
 	QIcon m_icon = QIcon(m_pix);
	QListWidgetItem *m_item =new QListWidgetItem(m_icon, "red");
//	QListWidgetItem *m_item =new QListWidgetItem(QIcon(":/UseColortDegate/icon/line1.jpg"), "red");
	ui.listWidget->insertItem(0, m_item);


  	ui.comboBox->insertItem(0, QIcon(":/UseColortDegate/icon/line1.jpg"), "");
  	ui.comboBox->insertItem(0, QIcon(":/UseColortDegate/icon/pst.png"), "");


	QStandardItemModel *model = new QStandardItemModel(2,2);
	
	ui.tableView->setModel(model);
	QxColorDelegate *m_delete = new QxColorDelegate;
	ui.tableView->setItemDelegateForColumn(0, m_delete);
	ui.tableView->setItemDelegateForColumn(1, m_delete);

	QColor color = QColor(0xff000000);
	QPixmap pixmap = QPixmap(10,10);
	pixmap.fill(color);
	QIcon coloricon = QIcon(pixmap);
	QStandardItem *item = new QStandardItem(coloricon, "Black");
	QStandardItem *item2 = new QStandardItem(coloricon, "Black");
	item->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled);
	model->setItem(0, 0, item);
	model->setItem(1, 0, item2);
	ui.tableView->setEditTriggers(QAbstractItemView::AllEditTriggers);
	
//	ui.tableView->installEventFilter(this);
}

UseColortDegate::~UseColortDegate()
{

}

void UseColortDegate::on_listWidget_itemClicked(QListWidgetItem *item)
{
	connect(this, SIGNAL(itemPressed(int)), ui.colorComboBox, SLOT(slot_setComboBox(int)));

	emit itemPressed(6);
}

// bool UseColortDegate::eventFilter( QObject *target, QEvent *event)
// {
// 	int i = 0;
// 	if (target == ui.tableView)
// 	{
// 		if (event->type() == QEvent::MouseButtonDblClick)
// 		{
// 			i = 1; 
// 			return true;
// 		}
// 		if (event->type() == QEvent::MouseButtonPress)
// 		{
// 			i = 2;
// 		}
// 	}
// 	return QDialog::eventFilter(target, event);
// }

/*
void UseColortDegate::on_tableView_itemClicked(QListWidgetItem *item)
{
	editItem(item);
}
*/